package cc.fs.androidcode.ui.draw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import cc.fs.androidcode.utils.L;
import cc.fs.androidcode.utils.PxUtils;

/**
 * Created by fostion on 2015/12/9.
 */
public class MyView extends View{

    private int size = 60;

    public MyView(Context context) {
        super(context);
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 控制view的大小
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        L.e(" child view  onMeasurewidth   MeasureSpec:" + widthMeasureSpec +"   heightMeasureSpec:"+heightMeasureSpec);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        setMeasuredDimension(PxUtils.dip2px(getContext(),size),PxUtils.dip2px(getContext(),size));
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        L.e(" child view  onDraw");
        super.onDraw(canvas);

        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setAntiAlias(true);
        int width = size;
        int height = 60;
        int radius = Math.min(width,height)/2;
        canvas.drawCircle(width/2,height/2,radius,paint);

    }
}
